package cc.taofoo.Design.Prototype;


import java.io.*;

public class Customer implements Cloneable, Serializable {
    private Address address;

    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }

    public Object deepClone() {

        try {
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(bao);
            objectOutputStream.writeObject(this);

            ByteArrayInputStream bai = new ByteArrayInputStream(bao.toByteArray());
            ObjectInputStream objectInputStream = new ObjectInputStream(bai);

            objectOutputStream.close();
            objectInputStream.close();

            return objectInputStream.readObject();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }


    @Override
    public String toString() {
        return "Customer{" +
                "address=" + address +
                '}' + "---->" + hashCode();
    }
}
